package cn.tangwei.order.controller;

import cn.tangwei.basic.utils.AjaxRusult;
import cn.tangwei.basic.utils.LoginContext;
import cn.tangwei.basic.utils.PageList;
import cn.tangwei.order.domain.AdoptOrder;
import cn.tangwei.order.query.AdoptOrderQuery;
import cn.tangwei.order.service.IAdoptOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    /**
     * 领养订单下单接口
     * @param map
     * @param request
     * @return
     */
    @PostMapping("/submit")
    public AjaxRusult submit(@RequestBody Map<String, Object> map, HttpServletRequest request){
        try {
            String payData = adoptOrderService.submit(map, LoginContext.currentLoginInfo(request));
            System.out.println(payData);
            return AjaxRusult.me().setResultObj(payData);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxRusult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }
    }

    /**
     * 平台管理员工和店铺员工接口
     * @param query
     * @param request
     * @return
     */
    @PostMapping("/admin")
    private PageList<AdoptOrder> admin(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.admin(query, LoginContext.currentLoginInfo(request));
    }

    /**
     * 主站用户
     * @param query
     * @param request
     * @return
     */
    @PostMapping("/user")
    private PageList<AdoptOrder> user(@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adoptOrderService.user(query, LoginContext.currentLoginInfo(request));
    }

    @GetMapping("/{id}")
    public AdoptOrder getInfo(@PathVariable("id") Long id){
        return adoptOrderService.queryById(id);
    }


}
